﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;

namespace Quản_Lý_Thư_Viện
{
    class TacgiaDataAccess
    {
        private DataProvider _provider = new DataProvider();
        public TacgiaDataAccess()
        {
            _provider.connect();
        }
        public void inserttacgia(tacgiainfo info)
        {
            DataTable dt = new DataTable();
            dt = LayDSTacgia();
            int i = dt.Rows.Count+1;
            string insertCommand = "insert into dbo.TACGIA (MATG,TENTG) values('TG" + i + "'," + "N'" + info.Tentg + "')";
            _provider.executeNonQuery(insertCommand);
        }
        public void updatetacgia(tacgiainfo info)
        {
            string updateCommand = "update dbo.TACGIA set TENTG = N'" + info.Tentg
                + "' Where MATG = '" + info.Matg + "'";
            _provider.executeNonQuery(updateCommand);
        }
        public void deletetacgia(tacgiainfo info)
        {
            string deleteCommand = " Delete from dbo.TACGIA where MATG = '" + info.Matg + "'";
            _provider.executeNonQuery(deleteCommand);
        }
        public DataTable LayDSTacgia()
        {
            return _provider.GetData("select * from dbo.TACGIA order by MATG desc");
        }
        public DataTable timtg()
        {
            return _provider.GetData("select * from TACGIA where TENTG like '" + frmLoaiTacGia.timtg+ "%'");
        }
    }
}
